package com.yvan.game.merge.controller;

import com.yvan.game.merge.service.UserService;
import com.yvan.game.merge.support.Model;
import com.yvan.game.merge.support.ModelOps;
import com.yvan.game.merge.vo.UserState;
import com.yvan.platform.JsonWapper;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/state")
    public Model<UserState> getUserState(@RequestParam("userId") String userId) {
        return Model.newSuccess(userService.selectState(userId));
    }

    @PostMapping("/saveSeat")
    public ModelOps saveSeat(JsonWapper jw) {
        val userId = jw.asStr("userId");
        val seatArray = jw.asObject(int[].class, "seatArray");
        return ModelOps.newSuccess(userService.saveSeat(userId, seatArray));
    }

}
